package mainControlsTest;

import junit.framework.TestCase;
import mainControls.CoreCourseChecker;
import smallTools.SimpleTime;
import entities.AcdcProgram;
import entities.Course;
import entities.Room;
import entities.Section;
import entities.Staff;

public class CoreCourseCheckerTest extends TestCase {
	private CoreCourseChecker m_coreCourseChecker;

	public void setUp() {
		m_coreCourseChecker = new CoreCourseChecker();
	}

	public void tearDown() {
		Room.clear();
		Section.clear();
		Staff.clear();
		Course.clear();
		AcdcProgram.clear();
	}

	public void test_normal() {
		new AcdcProgram("BScCS");
		Section section1 = new Section("CS1_C01", 40, 2, "Staff01");
		String[] strPrograms = { "BScCS" };
		Course course1 = new Course("CS1", strPrograms);
		course1.addLecture("CS1_C01");
		SimpleTime startTime1 = new SimpleTime("Mon", 11, 30);
		boolean result = m_coreCourseChecker.check(section1, course1,
				startTime1);
		assertEquals(true, result);
	}

	public void test_lectureOverlap() {
		new AcdcProgram("BScCS");
		String[] strPrograms = { "BScCS" };
		Section section1 = new Section("CS1_C01", 40, 2, "Staff01");
		Course course1 = new Course("CS1", strPrograms);
		course1.addLecture("CS1_C01");

		Section section2 = new Section("CS2_C01", 40, 2, "Staff02");
		Course course2 = new Course("CS2", strPrograms);
		course2.addLecture("CS2_C01");

		SimpleTime startTime1 = new SimpleTime("Mon", 11, 30);
		section1.setSectionStartTime(startTime1);

		boolean result = m_coreCourseChecker.check(section2, course2,
				startTime1);
		assertEquals(false, result);
	}

	public void test_tutorialOverlap() {
		new AcdcProgram("BScCS");
		String[] strPrograms = { "BScCS" };
		Section section1T1 = new Section("CS1_T01", 40, 2, null);
		Course course1 = new Course("CS1", strPrograms);
		course1.addTutorial("CS1_T01");

		Section section2T1 = new Section("CS2_T01", 40, 2, null);
		Section section2T2 = new Section("CS2_T02", 40, 2, null);
		Course course2 = new Course("CS2", strPrograms);
		course2.addTutorial("CS2_T01");
		course2.addTutorial("CS2_T02");

		Section section3 = new Section("CS3_C01", 40, 2, null);
		Course course3 = new Course("CS3", strPrograms);
		course3.addLecture("CS3_C01");

		section1T1.setSectionStartTime(new SimpleTime("Mon", 11, 30));
		section2T1.setSectionStartTime(new SimpleTime("Tue", 11, 30));
		section2T2.setSectionStartTime(new SimpleTime("Wed", 11, 30));

		boolean result1 = m_coreCourseChecker.check(section3, course3,
				new SimpleTime("Mon", 11, 30));
		assertEquals(false, result1);

		boolean result2 = m_coreCourseChecker.check(section3, course3,
				new SimpleTime("Tue", 11, 30));
		assertEquals(false, result2);

		boolean result3 = m_coreCourseChecker.check(section3, course3,
				new SimpleTime("Wed", 11, 30));
		assertEquals(false, result3);
	}
}
